<template>
  <div class="layout">
    <el-container v-if="state.showMenu" class="container">
      <el-aside class="aside">
        <div class="head">
          <div>
            <img
              src="https://www.watabe-wedding.com.cn/upload/watabe/China/logo.svg"
              alt="logo"
            />
            <!-- <span>vue3 admin</span> -->
          </div>
        </div>
        <!-- <div class="line" /> -->
        <el-menu
          :default-openeds="state.defaultOpen"
          :router="true"
          :default-active="state.currentPath"
        >
          <el-submenu index="1">
            <template #title>
              <span>首页配置</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/store"
                ><i class="el-icon-s-shop" />门店配置</el-menu-item
              >
              <el-menu-item index="/banner"
                ><i class="el-icon-picture" />首页轮播图</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template #title>
              <span>精选服务</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/server-category"
                ><i class="el-icon-menu" />服务分类</el-menu-item
              >
            </el-menu-item-group>
            <el-menu-item index="/server"
                ><i class="el-icon-document" />服务配置</el-menu-item
              >
            <el-menu-item index="/server2"
                ><i class="el-icon-document" />服务配置（新）</el-menu-item
              >
          </el-submenu>
          <el-submenu index="3">
            <template #title>
              <span>作品管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/user"
                ><i class="el-icon-user-solid" />用户配置</el-menu-item
              >
              <el-menu-item index="/works-type"
                ><i class="el-icon-location" />作品地点</el-menu-item
              >
              <el-menu-item index="/works"
                ><i class="el-icon-document" />作品配置</el-menu-item
              >
              <el-menu-item index="/work-type"
                ><i class="el-icon-menu" />作品分类(新版)</el-menu-item
              >
              <el-menu-item index="/work"
                ><i class="el-icon-document" />作品配置(新版)</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="4">
            <template #title>
              <span>报价管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/quotation-category"
                ><i class="el-icon-menu" />报价分类</el-menu-item
              >
            </el-menu-item-group>
            <el-menu-item index="/quotation"
                ><i class="el-icon-document" />报价配置</el-menu-item
              >
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container class="content">
        <Header />
        <div class="main">
          <router-view />
        </div>
        <Footer />
      </el-container>
    </el-container>
    <el-container v-else class="container">
      <router-view />
    </el-container>
  </div>
</template>

<script>
import { reactive } from "vue";
import { useRouter } from "vue-router";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";

export default {
  name: "App",
  components: {
    Header,
    Footer,
  },
  setup() {
    const noMenu = ["/login"];
    const router = useRouter();
    const state = reactive({
      defaultOpen: ["1", "2", "3", "4"],
      showMenu: true,
      currentPath: "/dashboard",
      count: {
        number: 1,
      },
    });
    router.beforeEach((to, from, next) => {
      if (to.path == "/login") {
        // 如果路径是 /login 则正常执行
        next();
      } else {
        // 如果不是 /login，判断是否有 token
        // if (!localGet("token")) {
        //   // 如果没有，则跳至登录页面
        //   next({ path: "/login" });
        // } else {
        //   // 否则继续执行
        //   next();
        // }
        next();
      }
      state.showMenu = !noMenu.includes(to.path);
      state.currentPath = to.path;
    });
    return {
      state,
    };
  },
};
</script>

<style scoped>
.layout {
  min-height: 100vh;
  background-color: #ffffff;
}
.container {
  height: 100vh;
}
.aside {
  width: 200px !important;
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  background-color: #fff;
  overflow: hidden;
  overflow-y: auto;
  -ms-overflow-style: none;
  overflow: -moz-scrollbars-none;
}
.aside::-webkit-scrollbar {
  display: none;
}
.head {
  display: flex;
  border-bottom: 1px solid #e9e9e9;
  align-items: center;
  justify-content: center;
  height: 50px;
}
.head > div {
  display: flex;
  align-items: center;
}

.head img {
  width: auto;
  height: 30px;
  margin-right: 10px;
}
.head span {
  font-size: 20px;
  color: #ffffff;
}
.line {
  border-top: 1px solid hsla(0, 0%, 100%, 0.05);
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}
.content {
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  overflow: hidden;
}
.main {
  height: calc(100vh - 100px);
  overflow: auto;
  padding: 10px;
}
</style>
<style lang="scss">
@import "@/element-variables";
body {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.el-menu {
  border-right: none !important;
}
.el-submenu {
  // border-top: 1px solid hsla(0, 0%, 100%, 0.05);
  // border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}
.el-submenu:first-child {
  border-top: none;
}
.el-submenu [class^="el-icon-"] {
  vertical-align: -1px !important;
}
a {
  color: $--color-primary;
  text-decoration: none;
}
.el-pagination {
  text-align: center;
  margin-top: 20px;
}
.el-popper__arrow {
  display: none;
}
</style>
